# 持久化数据
import os

import yaml


# 写入yaml（使用追加数据的方式）
def write_yaml(data):
    with open(os.getcwd() + '/extract.yaml', encoding='utf-8', mode='a+') as f:
        yaml.dump(data, stream=f, allow_unicode=True)


# 读取
def read_yaml(key):
    with open(os.getcwd() + '/extract.yaml', encoding='utf-8', mode='r') as f:
        load = yaml.load(f, yaml.FullLoader)
        return load[key]


# 清空
def clear_yaml():
    with open(os.getcwd() + '/extract.yaml', encoding='utf-8', mode='w') as f:
        f.truncate()


# =========数据驱动读取yaml========
def get_data_yaml(yaml_path):
    with open(yaml_path, "r", encoding='utf-8') as f:
        load = yaml.safe_load(f)
        return load
